package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.esm.model.User;
import com.esm.service.ArriveService;
import com.esm.serviceimpl.ArriveServiceImpl;

import net.sf.json.JSONObject;
/**
 * 
 * @author zyj
 *
 */
public class ArriveController extends HttpServlet{
	ArriveService as=new ArriveServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		HttpSession session=req.getSession();
		User curUser=(User) session.getAttribute("currentUser");
		int uid=curUser.getUid();
		SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df2=new SimpleDateFormat("yyyy-MM-dd");
		Date nowDate=new Date();
		String start=df.format(nowDate);
		String sgroup=df2.format(nowDate);
		boolean addFlag=false;
		if(as.addStart(uid, start, sgroup)){
			addFlag=true;
		}
		JSONObject j=new JSONObject();
		j.put("addFlag", addFlag);
		PrintWriter pw=resp.getWriter();
		pw.write(j.toString());
	}
	
}
